import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { ENTRY } from '../../../enter';
import { logItemsEntity, stateResEntity, PostRequest } from './account-details.entity';



@Injectable({
  providedIn: 'root'
})
export class AccountDetailsService {
  
  private headers: HttpHeaders;
  constructor(private http: HttpClient) {
    this.headers = new HttpHeaders();
    this.headers.set('Content-Type', 'application/json');
  }
  private getInfoUrl = '/api/bank/getinfo/';
  private postDecUrl = '/api/bank/decreaseMoney';
  private postIncUrl = '/api/bank/increaseMoney';
  public getRemainingMoney(name: string): Observable<stateResEntity> {
    return this.http.get<stateResEntity>(this.getInfoUrl + name, {
      headers: this.headers
    });
  }
  public postDecRemainingMoney(name_: string, money_: number ): Observable<stateResEntity> {
    let postData: PostRequest;
    postData = { name: name_, money: money_ };
    return this.http.post<stateResEntity>(this.postDecUrl, postData);
  }

  public postIncRemainingMoney(name_: string, money_: number ): Observable<stateResEntity> {
    let postData: PostRequest;
    postData = { name: name_, money: money_ };
    return this.http.post<stateResEntity>(this.postIncUrl, postData);
  }

  public getlogItemsWhole(name: string) {
    let logItems: logItemsEntity[] = [
      // {
      //   time: '2021-01-28',
      //   type: '存款',
      //   moneyCount: 100000,
      // },
      // {
      //   time: '2021-01-27',
      //   type: '提款',
      //   moneyCount: 159,
      // },
      // {
      //   time: '2021-01-29',
      //   type: '存款',
      //   moneyCount: 142,
      // },
      // {
      //   time: '2021-01-23',
      //   type: '提款',
      //   moneyCount: 159,
      // },
      // {
      //   time: '2021-01-24',
      //   type: '提款',
      //   moneyCount: 159,
      // },
      // {
      //   time: '2021-01-25',
      //   type: '提款',
      //   moneyCount: 159,
      // },
    ];
    return logItems;
  }
}
